﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using Top.Api.Domain;
using System.ComponentModel.DataAnnotations;

namespace TopActivityLibrary
{
    public class TopContext : DbContext
    {
        public TopContext()
            : base("TopContext")
        {
            Database.SetInitializer<TopContext>(new DropCreateDatabaseIfModelChanges<TopContext>());
        }
        public DbSet<Item> Items { get; set; }
        //public IDbSet<CollectItem> CollectItems { get; set; }
        public DbSet<Trade> Trades { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Item>().HasKey(e => e.NumIid);
            modelBuilder.Entity<Item>().Property(e => e.NumIid).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            //modelBuilder.Entity<CollectItem>().HasKey(e => e.ItemNumid);
            //modelBuilder.Entity<CollectItem>().Property(e => e.ItemNumid).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            modelBuilder.Entity<Trade>().HasKey(e => e.NumIid);
            modelBuilder.Entity<Trade>().Property(e => e.NumIid).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            modelBuilder.Entity<Order>().HasKey(e => e.NumIid);
            modelBuilder.Entity<Order>().Property(e => e.NumIid).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            modelBuilder.ComplexType<Location>();

            base.OnModelCreating(modelBuilder);
        }
    }
}